﻿using System;
using System.Collections.Generic;
using Models;
using System.Web.Http;

namespace WebApp.Controllers
{
    [RoutePrefix("api/Category")]
    public class CategoryABCController : ApiController
    {
        Services.CategoryServices services = new Services.CategoryServices();

        [HttpGet]
        [Route("GetAll")]
        public IHttpActionResult GetAll()
        {
            List<Category> list = services.GetList(t => t.CategoryName != "");
            return Json(list);
        }

        [HttpPost]
        [Route("Save")]
        public int Save(Category objCategory)
        {
            return services.Save(objCategory);
        }

        [HttpPost]
        [Route("Delete")]
        public int Delete(string id)
        {
            return services.Delete(id);
        }

        [HttpPost]
        [Route("Exists")]
        public bool Exists(Category objCategory)
        {
            return services.Exists(t => t.CategoryName == objCategory.CategoryName && t.CategoryId != objCategory.CategoryId);
        }
    }
}
